created by aha00a at 2022-07-21
last modified by aha00a at 2022-07-21
revision: 2

JavaScript On Without jQuery

https://jsfiddle.net/7b0dL5yw/

function jQueryOn(selector, event, childSelector, handler) {
    var is = function(node, selector) {
        return (node.matches || node.matchesSelector || node.msMatchesSelector || node.mozMatchesSelector || node.webkitMatchesSelector || node.oMatchesSelector).call(node, selector);
    };

    var nodeList = document.querySelectorAll(selector);
    for (var i = 0; i < nodeList.length; i++) {
        var node = nodeList[i];
        node.addEventListener(event, function(e) {
            if (is(e.target, childSelector)) {
                handler(e);
            }
        });
    }
}

jQueryOn('table', "click", 'td', function(e) {
    console.log(e);
    e.target.style.backgroundColor = 'red';
});

--2022-07-21

1. See Also

1.2. Similar Pages

Similar pages by cosine similarity. Words after page name are term frequency.

1.3. Adjacent Pages